﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using Core = Com.Oxilly.Qsb.Core;
using Com.Oxilly.Qsb.Core.SDK.Events;

namespace Com.Oxilly.Qsb.Services
{
    public partial class WcfHost : ServiceBase
    {
        ServiceHost serviceHost;
        Core.Engine engine;

        public WcfHost()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                if (serviceHost != null)
                {
                    serviceHost.Close();
                }
                if (engine != null)
                {
                    engine.Api.Halt();
                }
                engine = new Core.Engine();
              
                QsbCommandService service = new QsbCommandService();
                
                service.SetEngine(engine);
                serviceHost = new ServiceHost(service);
                serviceHost.Open();

                engine.Api.Start();
                
            }
            catch (Exception ex)
            {
            }
        }

   

        protected override void OnStop()
        {
            if (engine != null)
            {
                engine.Api.Halt();
                engine = null;
            }
            if (serviceHost != null)
            {
                serviceHost.Close();
                serviceHost = null;
            }
        }

    }
}
